package com.landmark;

import javax.swing.*;

public class UMProgressBar extends JFrame implements Runnable {

    public UMProgressBar() {
        super(Util.getHelperBean().getFilePath());
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        label = new JLabel();
        progressBar = new JProgressBar(0, Util.getHelperBean().getLineCount());
        progressBar.setStringPainted(true);
        panel.add(label);
        panel.add(progressBar);
        add(panel);
        //setAlwaysOnTop(true);
        setResizable(false);
        
        setBounds(Util.getHelperBean().getMainPanelWidth() / 2 , Util.getHelperBean().getMainPanelHeight() / 2 , 300, 75); // Size
        setVisible(true);
    }

    @Override
    public void run() {
        try {
            if (Util.getHelperBean().isProcessingDone()) {
                setVisible(false);
                dispose();
            }            
            label.setText(((Integer)Util.getHelperBean().getCurrentCount()).toString() + "/" + ((Integer)Util.getHelperBean().getLineCount()).toString());
            progressBar.setValue(Util.getHelperBean().getCurrentCount());
            progressBar.paintImmediately(progressBar.getVisibleRect());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void close() {        
        dispose();
    }
    JProgressBar progressBar = null;
    JLabel label = null;
}
